﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class User_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection strcon = Class1.DBconnection();
            strcon.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select * from tb_User where Username='"+Session["username"].ToString()+"'",strcon);
            DataSet ds = new DataSet();
            sda.Fill(ds,"tb_User");
            DataRowView rowview=ds.Tables["tb_User"].DefaultView[0];
            this.Label1.Text = Session["username"].ToString();
            this.Userpwd.Text = rowview["Userpwd"].ToString();
            this.CompanyName.Text = rowview["CompanyName"].ToString();
            for (int i = 1; i < this.UserType.Items.Count; i++)
            {
                if (this.UserType.Items[i].Text.ToString() == rowview["UserType"].ToString())
                {
                    this.UserType.Items[i].Selected = true;
                }
            }
            this.Linkman.Text = rowview["Linkman"].ToString();
            this.Tel.Text = rowview["Tel"].ToString();
            this.MobileTelephone.Text = rowview["MobileTelephone"].ToString();
            this.Email.Text = rowview["Email"].ToString();
            this.Address.Text = rowview["Address"].ToString();
            this.Postalcode.Text = rowview["Postalcode"].ToString();
            this.Problem.Text = rowview["Problem"].ToString();
            this.Answer.Text = rowview["Answer"].ToString();
            this.Bewrite.Text = rowview["Bewrite"].ToString();
            strcon.Close();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection strcon = Class1.DBconnection();
        strcon.Open();
        SqlCommand scd = new SqlCommand("update tb_User set Userpwd='" + Userpwd.Text.ToString() + "',CompanyName='" + CompanyName.Text.ToString() + "',UserType = '" + this.UserType.Text.ToString() + "',Linkman = '" + this.Linkman.Text.ToString() + "',Tel = '" + this.Tel.Text.ToString() + "',MobileTelephone ='" + this.MobileTelephone.Text.ToString() + "',Email = '" + this.Email.Text.ToString() + "',Address = '" + this.Address.Text.ToString() + "',Postalcode = '" + this.Postalcode.Text.ToString() + "',Bewrite = '" + this.Bewrite.Text.ToString() + "',Problem = '" + this.Problem.Text.ToString() + "',Answer = '" + this.Answer.Text.ToString() + "' where Username='" + Session["username"].ToString() + "'", strcon);
        scd.ExecuteNonQuery();
        Response.Write("<script language=javascript>alert('您已经修改成功！')</script>");
    }
}
